package com.homework;

import com.alibaba.dubbo.common.Constants;
import com.homework.bean.ConsumerComponent;
import com.homework.filters.TPMonitorFilter;
import com.homework.util.Consume;
import com.homework.util.ReportStatus;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.rpc.Filter;
import org.springframework.context.annotation.*;

import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ConsumerBoot {
    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();

        //Set<String> ss = ExtensionLoader.getExtensionLoader(Filter.class).getSupportedExtensions();

        //输出运行结果
        Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(new ReportStatus(), 5,5, TimeUnit.SECONDS);

        //创建线程池进行调用服务
        ConsumerComponent service = context.getBean(ConsumerComponent.class);
        Executor executor1 = Executors.newFixedThreadPool(10);
        executor1.execute(new Consume(service, "A"));

        Executor executor2 = Executors.newFixedThreadPool(10);
        executor2.execute(new Consume(service, "B"));

        Executor executor3 = Executors.newFixedThreadPool(10);
        executor3.execute(new Consume(service, "C"));

    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan("com.homework.bean")
    @EnableDubbo()
    static class ConsumerConfiguration {

    }
}
